package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrdersDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商家订单相关接口
 */
@Api(value = "/admin/order", tags = {"商家订单相关接口"})
@RestController("AdminOrderController")
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 订单搜索功能
     * @param ordersPageQueryDTO
     * @return
     */
    @ApiOperation(value = "订单搜索功能", notes = "订单搜索功能", httpMethod = "GET")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        return orderService.conditionSearch(ordersPageQueryDTO);
    }

    /**
     * 各个状态的订单数量统计
     * @return
     */
    @ApiOperation(value = "各个状态的订单数量统计", notes = "各个状态的订单数量统计", httpMethod = "GET")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statistics() {
        return orderService.statistics();
    }

    /**
     * 取消订单功能
     * @param ordersCancelDTO
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "OrdersCancelDTO", name = "ordersCancelDTO", value = "", required = true)
    })
    @ApiOperation(value = "取消订单功能", notes = "取消订单功能", httpMethod = "PUT")
    @PutMapping("/cancel")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        return orderService.AdminCancel(ordersCancelDTO);
    }

    /**
     * 查询订单详情功能
     * @param orderId 订单id
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "orderId", value = "订单id", required = true)
    })
    @ApiOperation(value = "查询订单详情功能", notes = "查询订单详情功能", httpMethod = "GET")
    @GetMapping("/details/{id}")
    public Result<OrdersDetailVO> details(@PathVariable("id") Long orderId) {
        return orderService.getOrderDetail(orderId);
    }

    /**
     * 接单功能
     * @param ordersConfirmDTO
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "OrdersConfirmDTO", name = "ordersConfirmDTO", value = "", required = true)
    })
    @ApiOperation(value = "接单功能", notes = "接单功能", httpMethod = "PUT")
    @PutMapping("/confirm")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        return orderService.confirm(ordersConfirmDTO);
    }

    /**
     * 拒单功能
     * @param ordersRejectionDTO
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "OrdersRejectionDTO", name = "ordersRejectionDTO", value = "", required = true)
    })
    @ApiOperation(value = "拒单功能", notes = "拒单功能", httpMethod = "PUT")
    @PutMapping("/rejection")
    public Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        return orderService.rejection(ordersRejectionDTO);
    }

    /**
     * 派送订单
     * @param orderId
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "orderId", value = "", required = true)
    })
    @ApiOperation(value = "派送订单", notes = "派送订单", httpMethod = "PUT")
    @PutMapping("/delivery/{id}")
    public Result delivery(@PathVariable("id") Long orderId) {
        return orderService.delivery(orderId);
    }

    /**
     * 完成订单
     * @param orderId
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "orderId", value = "", required = true)
    })
    @ApiOperation(value = "完成订单", notes = "完成订单", httpMethod = "PUT")
    @PutMapping("/complete/{id}")
    public Result complete(@PathVariable("id") Long orderId) throws Exception {
        return orderService.complete(orderId);
    }
}
